package com.yangbo.controller;

import com.yangbo.entiry.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Administrator
 * @Date 2018-10-15 9:06
 */
@RestController
public class HelloController {

    @Value("${server.port}")
    private Integer port;

    @GetMapping(value = "/user")
    public ResponseEntity<Map<String,Object>> user(@RequestParam(value = "name") String name) {
        User user = new User("yangbo",23);
        if(!user.getName().equals(name)) {
            return ResponseEntity.ok().body(new HashMap<>(2));
        }
        Map<String,Object> map = new HashMap<>(4);
        map.put("name",user.getName());
        map.put("age",user.getAge());
        map.put("port",port);
        return ResponseEntity.ok().body(map);
    }
}
